package com.serkol.ams.module.sys.controller;

import cn.hutool.core.bean.BeanUtil;
import com.serkol.ams.module.sys.entity.SysRole;
import com.serkol.ams.module.sys.entity.SysRole;
import com.serkol.ams.module.sys.service.SysRoleService;

import com.serkol.ams.module.sys.valid.SysMenuParams;
import com.serkol.ams.module.sys.valid.SysRoleParams;
import com.serkol.ams.utils.R;
import com.serkol.ams.vo.MyPage;
import com.serkol.ams.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 角色表
 *
 * @author zlj
 * @email 328727561@qq.com
 * @date 2024-04-17 11:28:08
 */
@RestController
@RequestMapping("sys/role")
public class RoleController {
    @Resource
    private SysRoleService service;

    /**
     * 列表
     */
    @GetMapping("/list")
    public Result list(@RequestParam(value = "page", defaultValue = "0") int page,
                       @RequestParam(value = "size", defaultValue = "10") int size){
        MyPage data = service.queryPage(page,size);

        return Result.success(data);
    }

    /**
     * 保存
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody SysRoleParams data) {
        SysRole permission = new SysRole();
        BeanUtil.copyProperties(data, permission);
        System.out.println("permission = " + permission);
        boolean flag = false;
        if (permission.getId() != null) {
            if (permission.getId() > 0) {
                flag = service.updateById(permission);
            } else {
                flag = service.save(permission);
            }
        } else {
            flag = service.save(permission);
        }


        return flag ? Result.success() : Result.failure();
    }



}
